package com.tinysand.advert.entity;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import javax.persistence.*;
import java.util.Date;

/**
 * 广告实体类，最终展示给用户的广告内容数据（根据推广计划、推广单元与推广限制生成）
 *
 * Created By TINY
 * Create Time 2020/2/15
 **/
@Data
@AllArgsConstructor
@NoArgsConstructor
@Entity
@Table(name = "ad_creative")
@EntityListeners(AuditingEntityListener.class) // 使用JPA审计自动维护日期
public class Advertisement {

    /* 广告表自增主键 */
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "id", nullable = false)
    private Long id;

    /* 广告名称 */
    @Column(name = "name", nullable = false)
    private String name;

    /* 广告类型：图片、文本、视频等 */
    @Column(name = "type", nullable = false)
    private Integer type;

    /* 广告物料类型，如可用于标识图片类型的广告是 png 还是 jpg */
    @Column(name = "material_type", nullable = false)
    private Integer materialType;

    /* 广告高度 */
    @Column(name = "height", nullable = false)
    private Integer height;

    /* 广告宽度 */
    @Column(name = "width", nullable = false)
    private Integer width;

    /* 广告内容大小 */
    @Column(name = "size", nullable = false)
    private Long size;

    /* 广告持续时长，只有视频不为0 */
    @Column(name = "duration", nullable = false)
    private Integer duration;

    /* 广告审核状态 */
    @Column(name = "audit_status", nullable = false)
    private Integer auditStatus;

    /* 上传广告的用户id */
    @Column(name = "user_id", nullable = false)
    private Long userId;

    /* 广告地址 */
    @Column(name = "url", nullable = false)
    private String url;

    @Column(name = "create_time", nullable = false)
    @CreatedDate // 使用JPA审计功能维护记录创建时间
    private Date createTime;

    @Column(name = "update_time", nullable = false)
    @LastModifiedDate // 使用JPA审计功能自动维护更新时间
    private Date updateTime;
}
